//
//  masegeTableViewCell.m
//  share
//
//  Created by lanou3g on 15/7/21.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "masegeTableViewCell.h"
#import "shareModel.h"
@implementation masegeTableViewCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}

//重写自定义初始化方法进布局
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if([super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        //初始化imageViewArr
        self.imageViewArr = [NSMutableArray array];
        //lable的布局
        self.masegeLable = [[UILabel alloc]initWithFrame:CGRectMake(5,0, self.frame.size.width - 5, 40)];
        //self.masegeLable.numberOfLines = 0;
        [self addSubview:self.masegeLable];
        
        //imageview的布局
//        for (int i = 0 ; i<_sharM.imageArr.count; i++) {
//            UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(10+i*(100 + 20), 15, 100, 150)];
//            imageView.backgroundColor = [UIColor lightGrayColor];
//            imageView.tag = 1000+i;
//            [self.imageViewArr addObject:imageView];
//            [self addSubview:imageView];
//        }
    
    }
    return self;
}

//重写setter方法
-(void)setSharM:(shareModel *)sharM{
    
    _sharM = sharM;
    self.masegeLable.text = _sharM.bodyStr;
    self.masegeLable.frame = CGRectMake(5, 0, self.frame.size.width - 10, [masegeTableViewCell stringHeight:_sharM.bodyStr]);
    self.masegeLable.numberOfLines = 0;
    self.cityLable.text = _sharM.cityStr;
    self.imageCountArr = _sharM.imageArr;
    //imageview的布局
    for (int i = 0 ; i<_sharM.imageArr.count; i++) {
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(10+i*(100 + 20), [masegeTableViewCell stringHeight:_sharM.bodyStr], 100, 150)];
        imageView.backgroundColor = [UIColor lightGrayColor];
        imageView.tag = 1000+i;
        [self.imageViewArr addObject:imageView];
        [self addSubview:imageView];
    }

    
}
//计算字符串长度
+(CGFloat)stringHeight:(NSString *)str
{
    //    设置字符串的属性
    NSDictionary *dic = @{NSFontAttributeName : [UIFont systemFontOfSize:17]};
    //    计算字符串的区域
    CGRect rect = [str boundingRectWithSize:CGSizeMake(300, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return rect.size.height;
}

@end
